<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class SmsTemplateRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

        $editRules = [
            'subject'          => 'required',
            'content'          => 'required',
            'related_activity' => 'required',
            'related_project'  => 'required',
            'sort'             => 'required|numeric',
        ];

        $createRules = [
            'subject'          => 'required',
            'content'          => 'required',
            'related_activity' => 'required',
            'related_project'  => 'required',
            'sort'             => 'required|numeric',
        ];

//        return array();

        $data = Request::all();
        //如果是编辑
        if ($data['formType'] == 'edit') {
            return $editRules;
        }
        //如果是创建
        if ($data['formType'] == 'create') {
            return $createRules;
        }
    }

    public function attributes()
    {
        $attributes = array(
            'blade' => '短信模板',
            'type'  => '接受者人群',
        );

        return $attributes;
    }

    public function messages()
    {
        $messages = [
            'required' => ':attribute为必填选项',
            'numeric'  => ':attribute必须为数字',
        ];

        return $messages;
    }
}
